<?php

/**
 * 微信排队叫号系统 - 排队叫号服务
 * Author: lishengcn.cn <eric@lishengcn.cn>
 * Time: 2014-11-3 04:44
 */

$c = new SaeCounter();
$c->incr('Queuing');
$num = $c->get('Queuing');

$mysql= new SaeMysql();
$sql = "select * from `Queuing` where `q_id` = '{$num}'";
$data = $mysql->getData($sql);
$user = $data[0][q_openid];
$id = $data[0][q_id];

include ("token.php");

$contentStr = "现在轮到你了，请尽快与服务员联系";
$contentStr = urlencode($contentStr);

$a = array("content" => "{$contentStr}");
$b = array("touser" => "{$user}", "msgtype" => "text", "text" => $a);

$post = json_encode($b);
$post = urldecode($post);
    
$url = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token={$access_token}";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_exec($ch);
curl_close($ch);

echo $num;
?>